import axios from '@/utils/request'
class Api {
  // 获取首页banner
  fetchHomeBanner(params = {}){
    return axios.get('/banner/list', { params })
  };
  // 获取分类列表
  fetchCates (params = {}) {
    return axios.get('/shop/goods/category/all', { params })
  
  };
  // 获取商品列表
  fetchItems(params = {}) {
    return axios.post('/shop/goods/list/v2', params)
  };
  // 获取商品详情
  fetchDetail(id:string){
    return axios.get('/shop/goods/detail', {params:{id}})
  
  };
  // 用户注册
  userReg(params= {}){
    return axios.post('/user/username/register', params)
  };
  // 用户登录
  userLogin(params = {}){
    return axios.post('/user/username/login', params)
  };
  // 加入购物车
  addCart(params = {}){
    return axios.post('/shopping-cart/add', params)
  
  };
  // 获取购物车中的信息
  fetchCartInfo(params?: {goodsId: string|number;number:number}){
    return axios.get('/shopping-cart/info', {params})
  };
  // 修改购物车商品购买数量
  changeCartNumber(params: {key: string;number: number}){
    return axios.post('/shopping-cart/modifyNumber', params)
  };
  // 修改购物车商品选中状态
  changeCartSelect(params: {key: string;selected: boolean}){
    return axios.post('/shopping-cart/select', params)
  };
  // 删除购物车中商品
  delCartItem (params: {key: string}){
    return axios.post('/shopping-cart/remove', params)
  
  }
}




export default new Api()

export const get = (url:string, params: any) => {
  return axios.get(url, { params })
}
export const post = (url:string, params: any) => {
  return axios.post(url, params)
}